import java.util.*;

public class TestLinkedList {
    public static void main1(String[] args) {
        //无参构造
        LinkedList<Integer> linkedList = new LinkedList<>();

        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        //其他容器构造
        LinkedList<Integer> linkedList1 = new LinkedList<>(arrayList);
        System.out.println(linkedList1);
    }

//    public static void main(String[] args) {
//        LinkedList<Integer> linkedList = new LinkedList<>();
//        linkedList.add(1);
//        linkedList.addFirst(0);
//        linkedList.set(1, 2);
//        linkedList.addLast(3);
//        linkedList.addLast(3);
//        linkedList.addLast(4);
//        linkedList.addLast(5);
//        System.out.println("当前元素个数：" + linkedList.size());
//        System.out.println(linkedList);
//        System.out.println("2元素在表吗？：" + linkedList.contains(2));
//        linkedList.remove(Integer.valueOf(3));
//        System.out.println(linkedList);
//        System.out.println("4在位置：" + linkedList.indexOf(4));
//        linkedList.clear();
//        System.out.println("清空后:" + linkedList);
//    }

    public static void main(String[] args) {
        List<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(5);

        //for循环
        System.out.println("=====for循环=====");
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
        System.out.println();

        //for-each循环
        System.out.println("=====for-each循环=====");
        for(Integer x : list) {
            System.out.print(x + " ");
        }
        System.out.println();

        //迭代器
        System.out.println("=====Iterator=====");
        Iterator<Integer> it = list.iterator();
        while(it.hasNext()) {
            System.out.print(it.next() + " ");
        }
        System.out.println();

        System.out.println("=====ListIterator=====");
        ListIterator lit = list.listIterator();
        while(lit.hasNext()) {
            System.out.print(lit.next() + " ");
        }
        System.out.println();

        System.out.println("=====逆序输出=====");
        lit = list.listIterator(list.size());
        while(lit.hasPrevious()) {
            System.out.print(lit.previous() + " ");
        }
        System.out.println();

    }
}
